package br.unesp.demac.ccn07.aula9.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Exemplo {
	
	Connection conexao;
	
	public Exemplo (String driver, String url,
			String name, String password) throws ClassNotFoundException, SQLException {
		Class.forName(driver);
		
		conexao = DriverManager.getConnection(url, name, password);
	}
	
	public void query() throws SQLException {
		String sql = "select nome, codigo from clientes order by nome";
		Statement stmt = conexao.createStatement();
		ResultSet rs = stmt.executeQuery(sql);
		
		while (rs.next()) {
			String nome = rs.getString("nome");
			String codigo = rs.getNString("codigo");
			System.out.println("Codigo = " + codigo + " Nome = " + nome);
		}
	}

	public static void main(String[] args) throws ClassNotFoundException, SQLException {
		String driver = "org.firebirdsql.jdbc.FBDriver";
		String url = "jdbc:firebirdsql:embedded:C:\\Users\\aluno\\Teste.gdb";
		String name = "SYSDBA";
		String password = "masterkey";
		Exemplo exemplo = new Exemplo(driver, url, name, password);
		exemplo.query();
	}

}
